package com.tzbank.back.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.back.service.ConfigPageToCustomerService;
import com.tzbank.entity.backstage.ConfigPageToCustomer;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 客服管理
 * @author tzbank
 *
 */
@Slf4j
@RestController
public class ConfigPageToCustomerController {

	@Autowired
	private ConfigPageToCustomerService configPageToCustomerService;

	/**
	 * 查询配置信息
	 * @param request
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月29日
	 */
//	@GetMapping(value = "selectCustomer")
//	public Map<String, Object> selectCustomer(HttpServletRequest request) {
//		try {
//			return this.configPageToCustomerService.selectCustomer();
//		} catch (Exception e) {
//			log.error("ConfigPageToCustomerController select: ", e);
//			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
//		}
//	}

	/**
	 * 查询配置信息
	 * @param request
	 * @param autoId
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月29日
	 */
	@GetMapping(value = "getCustomer")
	public Map<String, Object> getCustomer(HttpServletRequest request, @RequestParam(required = false) Integer autoId) {
		try {
			if(null == autoId || autoId.equals("")) {
				return this.configPageToCustomerService.selectCustomer();
			}else {
				return this.configPageToCustomerService.getCustomer(autoId);
			}
		} catch (Exception e) {
			log.error("ConfigPageToCustomerController get: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	/**
	 * 添加配置信息
	 * @param request
	 * @param customer
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月31日
	 */
	@PostMapping(value = "addCustomer")
	public Map<String, Object> addCustomer(HttpServletRequest request, @RequestBody ConfigPageToCustomer customer) {
		try {
			customer.setOperator("admin");
			return this.configPageToCustomerService.addCustomer(customer);
		} catch (Exception e) {
			log.error("ConfigPageToCustomerController add: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	/**
	 * 修改配置信息
	 * @param request
	 * @param customer
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月31日
	 */
	@PostMapping(value = "modifyCustomer")
	public Map<String, Object> modifyCustomer(HttpServletRequest request, @RequestBody ConfigPageToCustomer customer) {
		try {
			customer.setOperator("admin");
			return this.configPageToCustomerService.modifyCustomer(customer);
		} catch (Exception e) {
			log.error("ConfigPageToCustomerController modify: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	/**
	 * 删除配置信息
	 * @param request
	 * @param customer
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月31日
	 */
	@PostMapping(value = "deleteCustomer")
	public Map<String, Object> deleteCustomer(HttpServletRequest request, @RequestBody ConfigPageToCustomer customer) {
		try {
			return this.configPageToCustomerService.deleteCustomer(customer);
		} catch (Exception e) {
			log.error("ConfigPageToCustomerController delete: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

}
